package com.zyj.myapplication.Fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;

import com.zyj.myapplication.Activity.SearchActivity;
import com.zyj.myapplication.Adapter.ClubListAdapter;
import com.zyj.myapplication.Javabean.Club;
import com.zyj.myapplication.Model.ClubModel;
import com.zyj.myapplication.R;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class ClubFragment extends Fragment {
    private RecyclerView recyclerView;
   // private ImageView CL_search;
    private Club getAllclub;
    private View view = null;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_club, container, false);
        initViews();//初始化
        initEvents();//初始化事件
        return view;
    }

    public void initViews() {
     //   CL_search = (ImageView) view.findViewById(R.id.CL_search);
        recyclerView = (RecyclerView) view.findViewById(R.id.rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
    }

    public void initEvents() {
        ClubModel clubModel = new ClubModel();
        Call call = clubModel.getAllclub();
        call.enqueue(new Callback<List<Club>>() {
            @Override
            public void onResponse(Call<List<Club>> call, Response<List<Club>> response) {
                List<Club> club = response.body();
                recyclerView.setAdapter(new ClubListAdapter(getActivity(), club));
            }

            @Override
            public void onFailure(Call<List<Club>> call, Throwable t) {

            }
        });

       /* CL_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), SearchActivity.class);
                startActivityForResult(intent, 1);
                intent.getExtras();
            }
        });*/
    }


}
